﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace CoolCode.Controls.Test
{
    public partial class ModalDialogTest : UserControl, IModalDialogOpener
    {
        public ModalDialogTest()
        {
            InitializeComponent();
        }

        private void btnOpen_Click(object sender, RoutedEventArgs e)
        {
            var login = new Login();
            login.Closed += (sender2, args2) => CloseModalDialog();
            ShowModalDialog(login);
        }

        private void btnOpen2_Click(object sender, RoutedEventArgs e)
        {
            var form2 = new AnotherPage();
            form2.Closed += (sender2, args2) => CloseModalDialog();
            ShowModalDialog(form2);
        }

        //Popup p = new Popup();
        #region IModalDialogOpener implementations
        public void ShowModalDialog( ModalDialog dialog)
        {
            Window.ShowDialog(this.LayoutRoot, dialog);
          //  var  root=App.Current.RootVisual as UserControl     ;
           
          ////  var content = root.Content;
          //  if(root ==null)throw new Exception ("Error in convert Current RootVisual to UserControl ");
          //  Border placeHolder =root.FindName("placeHolder") as Border;
          //  if (placeHolder == null)
          //  {
          //      placeHolder = new Border
          //      {
          //          Name = "placeHolder",
          //          VerticalAlignment = VerticalAlignment.Stretch,
          //          HorizontalAlignment = HorizontalAlignment.Stretch,
          //          Background = new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)),
          //          Opacity = 0.7
          //      };
          //    root.eAdd(placeHolder);
          //  }
          //  placeHolder.Child = dialog;
          //  placeHolder.Visibility = Visibility.Visible;

            //p.Child = placeHolder;

            //// Set where the popup will show up on the screen.        
            //p.VerticalAlignment = VerticalAlignment.Stretch;
            //p.HorizontalAlignment = HorizontalAlignment.Stretch;

            //// Open the popup.
            //p.IsOpen = true;

        }

        public void CloseModalDialog()
        {
            Window.CloseDialog();
            //var placeHolder = this.LayoutRoot.FindName("placeHolder") as Border;
            //if (placeHolder != null)
            //{
            //    placeHolder.Child = null;
            //    placeHolder.Visibility = Visibility.Collapsed;
            //}
            //   p.IsOpen = false;
        }
        #endregion

    }
}
